//
//  LoginPublic.m
//  SpendMoney
//
//  Created by  lixinxin on 2017/9/22.
//  Copyright © 2017年  lixinxin. All rights reserved.
//

#import "LoginPublic.h"
#import "iPhoneType.h"
#import "MACID.h"
#import "SpendMoneyKeyChain.h"

@implementation LoginPublic

// 登录
+(void)loginMethod:(LoginMethodSelectBlock)callBack mobStr:(NSString *)mobStr pwdStr:(NSString *)pwd{

    NSString *iOSVersion = [iPhoneType phoneVersionMethod];
    NSString* iPhoneT = [iPhoneType iphoneTypeMethod];//方法在下面
    
    NSString *macStr = @"iOS";
    if ([MACID SSIDInfo]) {
        NSDictionary *macidDict = [MACID SSIDInfo];
        macStr = macidDict[@"BSSID"];
    }
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setValue:mobStr forKey:@"Mobile"];
    [dic setValue:pwd forKey:@"Password"];
    [dic setValue:iPhoneT forKey:@"PhoneModel"];
    [dic setValue:@"iPhone" forKey:@"PhoneBrand"];
    
    [dic setValue:[NSString stringWithFormat:@"%@",iOSVersion] forKey:@"PhoneSystemModel"];
    [dic setValue:[SpendMoneyKeyChain readUUIDFromKeyChain] forKey:@"DeviceId"];
    [dic setValue:macStr forKey:@"MACAddress"];
    
    [dic setValue:@2 forKey:@"Source"];  // 0:iOS  1:安卓
    [dic setValue:@"iOS" forKey:@"Channel"];  // 渠道
    
//    [dic setValue:[cSysPlist objectForKey:kLongitude] forKey:@"Longitude"];  // 经度
//    [dic setValue:[cSysPlist objectForKey:kLatitude] forKey:@"Latitude"];   // 维度

    [Network link:cLoginJRY parameters:dic outOfTime:0.f callback:^(Network *response) {
        
        if (response.responCode==1) {
            
            // 登录成功，
            ShareBorrowPublic_VC.afnetwordB = NO;
            
            NSMutableDictionary *responseDic = [NSMutableDictionary dictionaryWithDictionary:response.dataDic[@"resultObj"]];
            [responseDic setValue:mobStr forKey:@"PHONE"];
            [sharBaseTool setUserInfo:responseDic];
            
            // 判断是不是登录状态,如果是登录状态就去极光注册别名
            if ([sharBaseTool decrypt:User_ID]) {
                [[NSNotificationCenter defaultCenter] postNotificationName:kRegisterAlias object:@YES];
            }
            
            // 登录成功后，添加友盟账号统计
            [LoginPublic UMstatisticalMethod:response.dataDic[@"resultObj"][@"UserNo"]];
            
            if(callBack) callBack(response.dataDic[@"resultObj"], YES, nil);
            
        } else {
            callBack(nil, NO, response.dataDic[@"message"]);
        }
    }];
}

#pragma mark - 友盟统计账号
+ (void)UMstatisticalMethod:(NSString *)str {
    
    [ZZDHStatloginEvent mdf_UMClickStatisticalLogin:str];
}

@end
